﻿using GraphProcessor;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.ApplyRoutineAct, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_ApplyRoutineAct : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.ApplyRoutineAct;
        public override string name => LevelEditorConst.ApplyRoutineAct;
        [Output("目标", false)] public EditorLevelServiceTargetSetter tagOrMcid;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.ApplyRoutineAct, "LevelRoutineAct表ID")]
        public int actId;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rConfig = new LevelServiceExecutionCustom_ApplyRoutineAct()
            {
                actId = this.actId
            };
            tagOrMcid = new EditorLevelServiceTargetSetter(x => rConfig.tagOrMcid = x);
            return rConfig;
        }
        
        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_ApplyRoutineAct rNode)
            {
                this.actId = rNode.actId;
            }
            if (newConfig.customConfig is LevelServiceExecutionCustom_ApplyRoutineAct rConfig)
            {
                this.SyncTarget(rConfig.tagOrMcid, nameof(tagOrMcid));
            }
        }
    }
}